<template>
  <div class="page_body">
    <HomeTop :topTitle="topTitle"></HomeTop>
    <div class="userInfo_body">
      <div class="userInfo_btn_list">
        <div class="userInfo_btn" @click="toBaseViewFn()">
          <img
            class="userInfo_btn_icon"
            src="../../assets/image/user_info_icon01.png"
            style="width: 0.36rem; margin-right: 0.28rem"
          />
          <div class="userInfo_btn_name">基本信息</div>
          <img
            class="userInfo_btn_icon_to"
            src="../../assets/image/to_icon03.png"
          />
        </div>
        <div
          class="userInfo_btn"
          @click="toRegistrationViewFn()"
          v-if="sourceType != 2"
        >
          <img
            class="userInfo_btn_icon"
            src="../../assets/image/user_info_icon02.png"
            style="width: 0.45rem; margin-right: 0.21rem"
          />
          <div class="userInfo_btn_name">注册信息</div>
          <img
            class="userInfo_btn_icon_to"
            src="../../assets/image/to_icon03.png"
          />
        </div>
        <div
          class="userInfo_btn"
          @click="toVipViewFn()"
          v-if="
            sourceType != 2 &&
            (userInfoStatus.referee_level > 2 ||
              userInfoStatus.referee_level == 0)
          "
        >
          <img
            class="userInfo_btn_icon"
            src="../../assets/image/user_info_icon03.png"
            style="width: 0.41rem; margin-right: 0.22rem"
          />
          <div class="userInfo_btn_name">会员信息</div>
          <img
            class="userInfo_btn_icon_to"
            src="../../assets/image/to_icon03.png"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<style src="../../assets/css/user/userInfo.css" scoped></style>

<script>
import HomeTop from "@/components/homeTop.vue";
import { Toast } from "mint-ui";

export default {
  name: "UserInfo",
  components: {
    HomeTop,
  },
  data() {
    return {
      topTitle: "我的信息", // 顶部组件参数设置
      source: "", // 来源
      sourceType: 1, // 来源类型; 1. 总个人中心; 2. 教练员; 3. 裁判员
      userInfoStatus: {
        is_complete: 1, // 是否完善信息 1：否 2：是
        is_referee_pay: 1, // 是否支付注册 0：否 1：是
        is_referee_register: 1, // 是否提交过注册信息 0：否 1：是
        is_referee_vip_register: 1, // 是否提交过会员注册信息 0：否 1：是
        referee_level: 0, // 裁判员等级
      },
    };
  },
  created: function () {
    let query = this.$route.query;

    if (query.source != undefined && query.source != "") {
      this.source = query.source;
    }

    let coachIndex = this.source.indexOf("coach");
    let refereeIndex = this.source.indexOf("referee");

    if (coachIndex == 0) {
      this.sourceType = 2;
    } else if (refereeIndex == 0) {
      this.sourceType = 3;
    } else {
      this.sourceType = 1;
    }
    this.checkUserInfoFn();
  },
  methods: {
    // 查询填写数据
    checkUserInfoFn: function () {
      let that = this;
      let url = "/mobile/checkUserInfo";
      let data = {};
      this.axios
        .post(url, data)
        .then((response) => {
          if (response.code == 0) {
            that.userInfoStatus.is_complete = response.is_complete;
            that.userInfoStatus.is_referee_pay = response.is_referee_pay;
            that.userInfoStatus.is_referee_register =
              response.is_referee_register;
            that.userInfoStatus.is_referee_vip_register =
              response.is_referee_vip_register;
          } else {
            Toast({
              message: response.msg,
              duration: 3000,
            });
          }
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    // 查看基本信息
    toBaseViewFn: function () {
      if (this.userInfoStatus.is_complete == 2) {
        this.$router.push({
          name: "CoachImproveView",
        });
      } else {
        // 跳转至提示页提示填写
        if (this.sourceType == 2) {
          this.$router.push({
            name: "NoInfoTips",
            query: {
              source: 1,
            },
          });
        } else {
          this.$router.push({
            name: "NoInfoTips",
            query: {
              source: 2,
            },
          });
        }
      }
    },
    // 查看注册信息
    toRegistrationViewFn: function () {
      if (this.userInfoStatus.is_referee_register == 1) {
        this.$router.push({
          name: "RefereeRegisterOrderList",
        });
      } else {
        // 跳转至提示页提示填写
        this.$router.push({
          name: "NoInfoTips",
          query: {
            source: 3,
          },
        });
      }
    },
    // 查看会员信息
    toVipViewFn: function () {
      if (this.userInfoStatus.is_referee_vip_register == 1) {
        this.$router.push({
          name: "RefereeMemberView",
        });
      } else {
        // 跳转至提示页提示填写
        this.$router.push({
          name: "NoInfoTips",
          query: {
            source: 4,
          },
        });
      }
    },
  },
};
</script>
